"Admin module" taking over [Yii framework]

Posted by Flavius on Stack Overflow See other posts from Stack Overflow or by Flavius
Published on 2010-02-28T19:54:47Z Indexed on 2010/03/08 9:51 UTC
Read the original article Hit count: 734

Filed under:
|
|

Hi

I have an "admin" module and I want it to serve "dynamic controllers", i.e. to provide a default behaviour for controllers which don't really exist ("virtual controllers").

I've invented a lightweight messaging mechanism for loose communication between modules. I'd like to use it such that when e.g.

?r=admin/users/index

is requested, it will call the "virtual controller" "UserController" of AdminModule, which would, by default, use this messaging mechanism to notify the real module "UsersModule" it can answer to the request.

I thought about simulating this behaviour in AdminModule::init(), but at that point I have no way of deciding whether the action can be processed by a real controller or not, or at least I don't know how to do it.

This is because of the way Yii works: bottom-up, the controller is the one that renders the view AND the application layout (or the module's, if it exists), for example. I don't think the module even has a word to say about handling a given controller+action or not.

To recap, I'm looking for a kind of CWebModule::missingController($controllerId,$actionId), just like CController::missingAction($actionId), or a workaround to simulate that.

That would possibly be in CWebModule::init() or somewhere where I can find out

  1. whether the controller actually exists, in which case it's his job to handle it
  2. the $actionID and $controllerID
  3. whether the module $controllerID exists (I didn't type it wrong, in r=admin/users/index, "users" is the actual module, as specified in the application's config).

© Stack Overflow or respective owner

Related posts about yii

Related posts about php5